﻿using Efcore_Test.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Efcore_Test.Data.config
{
    public class CommentConfig : IEntityTypeConfiguration<Comment>
    {
        public void Configure(EntityTypeBuilder<Comment> builder)
        {
            builder.ToTable("T_Comment");
            builder.Property(x => x.Message).HasMaxLength(100).IsUnicode().IsRequired(false);

            //配置乐观锁
            builder.Property(x => x.Version).IsConcurrencyToken();
            //builder.Property(x => x.Version).IsRowVersion();

            builder.HasOne(x => x.Article).WithMany(x => x.Comments).HasForeignKey(x => x.ArticleId).IsRequired(); //1对多
            //全局查询条件 
            builder.HasQueryFilter(x => x.IsDeleted == false);
        }
    }
}
